package com.midea.ai.air.ui.more.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.ui.more.data.MoreLoggingItem;

import java.util.List;

/**
 * Created by ouyangdi on 2016/4/11.
 * 相关日志 logging 的Adapter
 */
public class MoreLoggingAdapter extends ArrayAdapter<MoreLoggingItem> {
    private LayoutInflater mInflater;

    public MoreLoggingAdapter(Context context, List<MoreLoggingItem> objects) {
        super(context, 0, objects);
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        MoreLoggingItem item = getItem(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item_more_logging, parent, false);
            holder = new ViewHolder();
            holder.tvTitle = (TextView) convertView.findViewById(R.id.more_logging_tv_title);
            holder.tvContent = (TextView) convertView.findViewById(R.id.more_logging_tv_context);
            holder.Img = (ImageView) convertView.findViewById(R.id.more_logging_iv);
            holder.line = (View) convertView.findViewById(R.id.more_logging_line);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.Img.setImageResource(item.getImg_Id());
        holder.tvTitle.setText(item.getmTitle());
        holder.tvContent.setText(item.getmContent());
        if (position == getCount() - 1) {
            holder.line.setVisibility(View.GONE);
        } else {
            holder.line.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

    public class ViewHolder {
        public TextView tvTitle;
        public TextView tvContent;
        public ImageView Img;
        public View line;
    }
}
